// src/utils/request.ts 数据请求的封装
import axios from "axios";
import { ElLoading } from "element-plus";
import router from "@/router";

const isDev = process.env.NODE_ENV === "development";

const request = axios.create({
  baseURL: isDev ? "" : "",
});

request.interceptors.request.use(
  (config) => {
    // 所有的请求去携带有 token 验证登录的信息
    //   config.headers.token = localStorage.getItem('token') || ''

    // 也可以展示loading动画
    ElLoading.service({
      lock: true,
      text: "Loading",
      background: "rgba(0, 0, 0, 0.7)",
    });
    return config;
  },
  (err) => {
    return Promise.reject(err);
  }
);

request.interceptors.response.use((response) => {
  ElLoading.service({
    lock: true,
    text: "Loading",
    background: "rgba(0, 0, 0, 0.7)",
  });

    return response

}, (err) => {
  return Promise.reject(err)
});

export default request;
